package com.star.pickstarbackend.mapper;

import com.star.pickstarbackend.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    // 根据用户名查询用户
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(@Param("username") String username);

    // 插入用户数据
    @Insert("INSERT INTO users (username, password, real_name, email, phone, role, status,avatar) " +
            "VALUES (#{username}, #{password}, #{realName}, #{email}, #{phone}, #{role}, #{status},#{avatar})")
    void insertUser(User user);

    //更新
    @Update("update users set real_name=#{realName},email=#{email},phone=#{phone} where id=#{id}")
    void update(User user);

    //更新用户头像
    @Update("update users set avatar=#{avatarUrl},updated_at=now() where id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    //更新用户密码
    @Update("update users set password=#{md5String},updated_at=now() where id =#{id} ")
    void updatePwd(String md5String, Integer id);
}